#include<bits/stdc++.h>
using namespace std;
void solve() {
    int n, w; cin >> n >> w;
    int weight[n], val[n];
    for (int i = 0; i < n; i++) cin >> weight[i];
    for (int i = 0; i < n; i++) cin >> val[i];

    int dp[w + 1] = {};
    for (int i = 0; i < n; i++)
        for (int j = w; j >= weight[i]; j--)
            dp[j] = max(dp[j], dp[j - weight[i]] + val[i]);
    cout << dp[w] << "\n";
}
int main() {
  solve();
  return 0;
}
